package com.atguigu.glkt.vod.controller;


import com.atguigu.ggkt.model.vod.Chapter;
import com.atguigu.ggkt.vo.vod.ChapterVo;
import com.atguigu.glkt.result.Result;
import com.atguigu.glkt.vod.service.ChapterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author shaoxuan
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/admin/vod/chapter")

public class ChapterController {

    @Autowired
    private ChapterService chapterService;

    /**
     * 1 获取章节小结列表
     * @param courseId
     * @return
     */
    @ApiOperation("大纲列表")
    @GetMapping("getNestedTreeList/{courseId}")
    public Result getNestedTreeList(
            @ApiParam(value = "课程ID", required = true)
            @PathVariable String courseId){
        List<ChapterVo> chapterVoList = chapterService.getNestedTreeList(courseId);
        return Result.ok(chapterVoList);
    }

    /**
     * 2 添加章节
     * @param chapter
     * @return
     */
    @ApiOperation("添加章节")
    @PostMapping("save")
    public Result save(@RequestBody Chapter chapter) {
        chapterService.save(chapter);
        return Result.ok(null);
    }

    /**
     * 3 修改-根据id查询
     * @param id
     * @return
     */
    @ApiOperation("修改-根据id查询")
    @GetMapping("get/{id}")
    public Result get(@PathVariable String id){
        Chapter chapter = chapterService.getById(id);
        return Result.ok(chapter);
    }

    /**
     * 4 修改-最终实现
     * @param chapter
     * @return
     */
    @ApiOperation("修改-最终实现")
    @PutMapping("update")
    public Result update(@RequestBody Chapter chapter) {
        chapterService.updateById(chapter);
        return Result.ok(null);
    }

    /**
     * 5 删除章节
     * @param id
     * @return
     */
    @ApiOperation("删除章节")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        chapterService.removeById(id);
        return Result.ok(null);
    }


}

